package com.googlecode.garbagecan.springsecuritystudy;


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;

public class HttpBasicTest {

	public static void main(String[] args) throws Exception {
		String username = "admin";
		String password = "admin";
		byte[] token = (username + ":" + password).getBytes("utf-8");
		String authorization = "Basic " + new String(Base64.encodeBase64(token), "utf-8");

		URL url = new URL("http://localhost:9000/index.jsp");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		conn.setRequestProperty("Authorization", authorization);
		conn.connect();
		
		BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		String line = null;
		while ((line = br.readLine()) != null) {
			System.out.println(line);
		}
	}
}
